package com.traffic.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.traffic.base.BaseAction;
import com.traffic.domain.BaseBean;
import com.traffic.domain.User;
import com.traffic.util.StrUtil;

@Controller
@Scope("prototype")
@SuppressWarnings("serial")
public class UserAction extends BaseAction<User>{
	
	/**
	 * 通过ajax请求，获取用户信息
	 * @throws Exception
	 */
    public void show() throws Exception {
    	 Long userId = Long.parseLong("1");
         User user = userService.findUserById(userId);
         BaseBean baseBean = new BaseBean();
         baseBean.setEmail(user.getEmail());
         baseBean.setCardNumber(user.getCardNumber());
         baseBean.setName(user.getName());
         baseBean.setUserStatus(user.getStatus());
         baseBean.setPhoneNumber(user.getPhoneNumber());
         baseBean.setUserId(user.getId());
         StrUtil.sendJson(baseBean);
    }
    /**
	 * 通过ajax请求，获取用户信息
	 * @throws Exception
	 */
    public String modify() throws Exception {
        
    	Long id =  Long.parseLong(request("userId"));
    	String name= request("name");
    	String cardNumber = request("cardNumber");
    	String email = request("email");
    	String phoneNumber = request("phoneNumber");
    	User user = userService.findUserById(id);
    	user.setCardNumber(cardNumber);
    	user.setEmail(email);
    	user.setName(name);
    	user.setPhoneNumber(phoneNumber);
    	user.setStatus((long) 1);
    	userService.update(user);
        return "toSuccess";
    }
    /**
     * 转向主页面user.html
     * @return
     * @throws Exception
     */
    public String index() throws Exception {
   	     return "index";
    }
}
